同一台MySQL服务器启动多个端口

        首先安装二进制源码包的mysql

        安装到初始化数据库的时候,因为是多个端口,所以要根据配置文件来初始化多个数据库。

        比如有2个端口

        则要运行两次

1
2
./scripts/mysql_install_db --datadir=/home/mysql1 --user=mysql
./scripts/mysql_install_db --datadir=/home/mysql2 --user=mysql

        编辑配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[mysqld0]
port = 3300
socket = /tmp/mysql0.sock
pid-file = /home/mysql0/localhost.localdomain0.pid
datadir = /home/mysql0
#log = /data/mysql0/mysql0.log
user = mysql
skip-locking
skip-name-resolve
#skip-bdb
#skip-innodb
key_buffer = 128M
max_allowed_packet = 1M
table_cache = 864
sort_buffer_size = 1M
read_buffer_size = 512K
read_rnd_buffer_size = 1M
myisam_sort_buffer_size = 32M
thread_cache_size = 16
query_cache_size = 32M
thread_concurrency = 8
#skip-networking
wait_timeout=8
max_connections=512
max_connect_errors = 10000000
max_user_connections=20
#slow_queries=/data/mysql0slowquer.sql
#log_slow_queries=/data/mysql0slowquer.sql
#long_query_time=3
#log-bin=mysql0-bin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
[mysqld1]
port = 3301
socket = /tmp/mysql1.sock
pid-file = /home/mysql1/localhost.localdomain1.pid
datadir = /home/mysql1
#log = /data/mysql1/mysql1.log
user = mysql
skip-locking
skip-name-resolve
#skip-innodb
#skip-bdb
key_buffer = 128M
max_allowed_packet = 1M
table_cache = 864
sort_buffer_size = 1M
read_buffer_size = 512K
read_rnd_buffer_size = 1M
myisam_sort_buffer_size = 32M
thread_cache_size = 16
query_cache_size = 32M
thread_concurrency = 8
#skip-networking
wait_timeout=8
max_connections=512
max_connect_errors = 10000000
max_user_connections=20
#log_slow_queries=/data/mysql1slowquer.sql
#long_query_time=3
#log-bin=mysql1-bin

        把配置文件放在 /etc/my.cnf

        启动mysql

1
/usr/local/mysql/bin/mysqld_multi start 0-1

        这里的0或1是根据配置文件中 [mysqld0] 来定的。